import Vue from "vue";

export default {
    namespaced: true,
    state: {
        config: {
            timezone: null,
            precision: 8,
        },
    },
    getters: {
        filterNumeral: (state) => (num, format = {}) => {
            if (format instanceof Object) {
                format = Object.assign({mantissa: state.config.precision, trimMantissa: true}, format);
            }
            return numbro(num || 0).format(format);
        },
        filterDatetimeToTimestamp: (state) => (datetime) => {
            return Vue.prototype.$helper.makeDatetimeToTimestamp(datetime, state.config.timezone);
        },
        filterTimestampToDatetime: (state) => (timestamp, format) => {
            return Vue.prototype.$helper.makeTimestampToDatetime(timestamp, format, state.config.timezone);
        },
        // 获取moment时间对象
        timedDate:(state) => (datetime) => {
            return Vue.prototype.$helper.timedDate(datetime, state.config.timezone);
        },
        // 获取当天0点时间对象
        timedDayTimestamp:(state) => (datetime) => {
            return Vue.prototype.$helper.timedDayTimestamp(datetime, state.config.timezone);
        },
        // 获取当月1日0点时间戳
        timedMonthTimestamp:(state) => (datetime) => {
            return Vue.prototype.$helper.timedMonthTimestamp(datetime, state.config.timezone);
        },
    },
    mutations: {
        setTimezone(state, timezone) {
            state.config.timezone = timezone;
        }
    },
}
